package primetest.dto;

import java.util.Date;
import java.util.Calendar;

public class PatientDto {
	private int seq;
	private String name;
	private int gender;
	private Date birthDate;
	private String phoneNumber;
	private String birthDateStr = "";

	//You must declared default constructor for Framework.
	public PatientDto(){
		super();
	}

	public PatientDto(int seq, String name, int gender, Date birthDate, String phoneNumber){
		this.seq = seq;
		this.name = name;
		this.gender = gender;
		this.birthDate = birthDate;
		this.phoneNumber = phoneNumber;
		this.birthDateStr = birthDate.toString();
	}

	public PatientDto(PatientDto dto) {
		this.seq = dto.seq;
		this.name = dto.name;
		this.gender = dto.gender;
		this.birthDate = dto.birthDate;
		this.phoneNumber = dto.phoneNumber;
		this.birthDateStr = dto.birthDateStr;
	}

	public int getSeq() {
		return seq;
	}

	public void setSeq(int seq) {
		this.seq = seq;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getGender() {
		return gender;
	}

	public void setGender(int gender) {
		this.gender = gender;
	}

	public Date getBirthDate() {
		return birthDate;
	}

	public void setBirthDate(Date birthDate) {
		this.birthDate = birthDate;
	}


	public String getPhoneNumber() {
		return phoneNumber;
	}

	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}

	public String getBirthDateStr() {
		return birthDateStr;
	}

	public void setBirthDateStr(String birthDateStr) {
		this.birthDateStr = birthDateStr;
	}

	public String getGenderName() {
		if (gender == 1) {
			return "Male";
		} else {
			return "Female";
		}
	}

	public String getAge() {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date(System.currentTimeMillis()));
		int time = calendar.get(Calendar.YEAR);
		calendar.setTime(birthDate);
		return String.valueOf(time - calendar.get(Calendar.YEAR));
	}

	public void saveDate() {
		birthDateStr = birthDate.toString();
	}

	public void setAll(PatientDto dto) {
		this.seq = dto.seq;
		this.name = dto.name;
		this.gender = dto.gender;
		this.birthDate = dto.birthDate;
		this.phoneNumber = dto.phoneNumber;
		this.birthDateStr = dto.birthDateStr;
	}

	public boolean isValid() {
		if (name.length() == 0 || phoneNumber.length() == 0) {
			return false;
		}
		return true;
	}
}
